package cn.lanqiao.ui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import java.awt.event.ActionListener;
import java.beans.PropertyVetoException;
import java.awt.event.ActionEvent;

public class Login extends JFrame {

	private JPanel contentPane;
	public static JDesktopPane desktopPane=null;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 690, 491);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		this.setLocationRelativeTo(null);
		JMenu menu = new JMenu("报名选项");
		menuBar.add(menu);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		
		
		JMenuItem menuItem = new JMenuItem("立即报名");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//容器中有：激活，没有：创建
				String title="立即报名";
				//第一步：找到容器中的所有子窗体
				JInternalFrame[] chileFrames=desktopPane.getAllFrames();
				System.out.println(chileFrames.length);
				//第二步：遍历，查找
				boolean isExists=false;
				for(JInternalFrame f:chileFrames) {
					if(f.getTitle().equals(title)) {
						try {
							f.setSelected(true);
							isExists=true;
						} catch (PropertyVetoException e1) {
							e1.printStackTrace();
						}
						break;
					}
				
				}
				if(!isExists) {
					ApplyFrm applyFrm=new ApplyFrm();
					applyFrm.setVisible(true);
					desktopPane.add(applyFrm);
				    try {
						applyFrm.setSelected(true);
					} catch (PropertyVetoException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}
				
				
			}
			
		});
		menu.add(menuItem);
		desktopPane = new JDesktopPane();
		contentPane.add(desktopPane, BorderLayout.CENTER);
	}

}
